<?php

$con = mysqli_connect('localhost','root','123456','goodsList');

  $username = $_POST['username'];
  $password = $_POST['password'];

  $sql = "SELECT * FROM `userlist` WHERE `username`='$username'";

  $res = mysqli_query($con,$sql);

  if (!$res) {
    die('error for mysql: ' . mysqli_error());
  }

  $row = mysqli_fetch_assoc($res);

  if (!$row) {
    $addSql = "INSERT INTO `userlist` VALUES (null, '$username', '$password')";

    $addRes = mysqli_query($con,$addSql);

    if(!$addRes){
        die('数据库链接错误' . mysqli_error($con));
    }
    echo json_encode(array(
      "code" => 0,
      "message" => "注册成功"
    ));

  } else {
    echo json_encode(array(
      "code" => 1,
      "message" => "注册失败"
    ));
  }

?>
